package com.china08.yxyapi.api.manage.tec.teaching.lesson.cloud.ques;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.china08.yxyapi.api.YxyApiBaseController;
import com.china08.yxyapi.entity.mg.user.YxyUserCenter;
import com.china08.yxyapi.entity.mg.user.YxyUserCenter.ResSubjectPhase;
import com.china08.yxyapi.model.YxyApiReqModel;
import com.china08.yxyapi.model.YxyApiRespModel;
import com.china08.yxyapi.repository.mg.YxyUserCenterRepository;

/**
 * 
 * @annotation: 云课程--查询用户对应知识点目录
 * @author: yaoguanglin
 */
@CrossOrigin
@RestController
public class QuesCloudLessonKnowCatalogStatusController extends YxyApiBaseController {

    @Autowired
    private YxyUserCenterRepository yxyUserCenterRepository;

    @RequestMapping(value = "/api_yw/manage/tec/teaching/lesson/cloud/ques/know/status/catalog/sch", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public RespModel precess(HttpServletRequest request, HttpServletResponse response,
            @RequestBody(required = false) ReqModel reqModel) {
        String userId = getProfile(request, response).getId();
        YxyUserCenter yxyUserCenter = yxyUserCenterRepository.findByUserId(userId);
        RespModel model = new RespModel();
        if (yxyUserCenter == null) {
            model.phaseId = "";
            model.phaseName = "";
            model.subId = "";
            model.subName = "";
            model.status = 0;
        } else {
            ResSubjectPhase lessonKnowView = yxyUserCenter.getLastCloudLessonKnowView();
            if (lessonKnowView != null && lessonKnowView != null) {
                model.phaseId = lessonKnowView.getPhaseId();
                model.phaseName = lessonKnowView.getPhaseName();
                model.subId = lessonKnowView.getSubjectId();
                model.subName = lessonKnowView.getSubjectName();
                model.status = 1;
            } else {
                model.phaseId = "";
                model.phaseName = "";
                model.subId = "";
                model.subName = "";
                model.status = 0;
            }
        }
        return model;
    }

    protected static class ReqModel extends YxyApiReqModel {
    }

    protected static class RespModel extends YxyApiRespModel {
        public String phaseName;
        public String phaseId;
        public String subName;
        public String subId;
        public Integer status;
    }
}
